package com.example.bgmachine.bgmachine.paycode;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.bgmachine.bgmachine.HttpsUtil;
import com.example.bgmachine.bgmachine.R;
import com.example.bgmachine.bgmachine.Urlinfor;
import com.example.bgmachine.bgmachine.createcode.QRCodeUtil;
import com.example.bgmachine.bgmachine.exts.CartDatas;
import com.example.bgmachine.bgmachine.homes.HomePages;
import com.example.bgmachine.bgmachine.waitviews.WeiboDialogUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;

public class PayCodes extends AppCompatActivity {

    private static final int PAYCODE_INFOR = 10;
    private static final int PAYCODE_CHECK = 11;

    private Context mContext = null;
    private ImageButton home_page_top_right_image_btn = null;

    private TextView home_page_top_right_device_textview = null;

    private Button pay_code_bottom_cancel = null;

    private TextView pay_code_mid_top_order_textview = null;
    private TextView pay_code_mid_top_time_textview = null;

    private TextView pay_code_mid_bottom_order_pay_textview = null;


    private String pay_code_mid_top_order_str = "";

    private String pay_code_mid_top_time_str = "";
    private String pay_code_mid_order_str = "";


    private String content;//二维码内容
    private float width, height;//宽度，高度
    private Bitmap qrcode_bitmap;//生成的二维码
    private String error_correction_level = "H";
    private String margin = "1";//容错率，空白边距
    private int color_black = Color.BLACK;
    private int color_white = Color.WHITE;//黑色色块，白色色块
    private Bitmap logoBitmap;//logo图片
    private Bitmap blackBitmap;//代替黑色色块的图片

    private ImageView iv_qrcode = null;


    private String mdevicenums = "";
    public String mimageInfors = "";

    private String mOrderInfors = "";
    public int mCurrentIndex = 0;

    public int mAllIndex = 120;

    private float mAllPrices = 0;
    private Dialog mWeiboDialog = null;
    private int mProgressIndex = 0;
    public Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Log.d("aaaaa", "ccccc: ");
            //   Toast.makeText(mContext, "myTopic myTopic="+myTopic , Toast.LENGTH_SHORT).show();
            switch (msg.what) {
                case PAYCODE_INFOR:
                    String responsa = (String) msg.obj;
                    Log.d("aaaaa", "responseinfor:responsa==" + responsa);

                    try {
                        JSONObject jsonObject = new JSONObject(responsa);
                        String code = jsonObject.optString("code");
                        Log.d("aaaaa", "responseinfor:code==" + code);

                        if (Integer.parseInt(code) == 200) { // || code == 1
                            WeiboDialogUtils.closeDialog(mWeiboDialog);
                            //JSONObject data = jsonObject.optJSONObject("data");
                            String datas = jsonObject.optString("data");
                            Log.d("aaaaa", "responseinfor:datas==" + datas);

                            JSONObject data = new JSONObject(datas);
                            String sub_code = data.optString("sub_code");
                            Log.d("aaaaa", "responseinfor:sub_code==" + sub_code);

                            // String codeUrl = data.optString("codeUrl"); //"weixin://wxpay/bizpayur1?pr=oXvPsPhzz";// jsonObject.optString("codeUrl");
                            //  String orderId = data.optString("orderId"); //"1611267799286546432";//jsonObject.optString("orderId");

                            //    CartDatas.getCartDatas().setCurrentOredrNumbers(orderId);
                            if (sub_code.equals("SUCCESS")) {
                                String qr_code = data.optString("qr_code");
                                String bank_order_no = data.optString("bank_order_no");
                                String out_order_no = data.optString("out_order_no");
                                String plat_trx_no = data.optString("plat_trx_no");
                                Log.d("aaaaa", "responseinfor:qr_code==" + qr_code);
                                CartDatas.getCartDatas().setBank_order_no(bank_order_no);
                                CartDatas.getCartDatas().setOut_order_no(out_order_no);
                                CartDatas.getCartDatas().setPlat_trx_no(plat_trx_no);
                                content = qr_code;
                                generateQrcodeAndDisplay();
                                mCheckDataHandler.sendEmptyMessageDelayed(212, 6000);

                            }

                        } else {
                            WeiboDialogUtils.closeDialog(mWeiboDialog);
                            Toast.makeText(mContext, mContext.getResources().getString(R.string.get_code_error), Toast.LENGTH_SHORT).show();

                            mRecordDataHandler.sendEmptyMessageDelayed(211, 3000);
                        }


                    } catch (JSONException e) {
                        e.printStackTrace();

                    }

                    break;

                case PAYCODE_CHECK:
                    String responsb = (String) msg.obj;
                    Log.d("aaaaa", "responseinfor:responsb==" + responsb);
                    mCheckDataHandler.removeMessages(212);
                    /*
                    try {
                        JSONObject jsonObject = new JSONObject(responsb);


                        if (jsonObject.has("resultInfo")) {

                            JSONObject resultInfo = jsonObject.optJSONObject("resultInfo");
                            int status = resultInfo.optInt("status");
                            JSONObject data = jsonObject.optJSONObject("data");
                            String customerId = data.optString("customerId");
                            if (customerId != null && customerId.length() > 0) { //|| status == 1
                                //   JSONObject data =jsonObject.optJSONObject("data");
                                //    String agentId = data.optString("agentId");
                                //     String shelfId = data.optString("shelfId");
                                //     String orderId = data.optString("orderId");

                            } else {
                                mCheckDataHandler.sendEmptyMessageDelayed(212, 6000);

                            }

                        } else {
                            mCheckDataHandler.sendEmptyMessageDelayed(212, 6000);

                        }
                    } catch (JSONException e) {
                        e.printStackTrace();

                    }
*/
                    try {
                        JSONObject jsonObject = new JSONObject(responsb);
                        String code = jsonObject.optString("code");
                        Log.d("aaaaa", "responseinfor:code==" + code);

                        if (Integer.parseInt(code) == 200) { // || code == 1

                            //JSONObject data = jsonObject.optJSONObject("data");
                            String datas = jsonObject.optString("data");
                            Log.d("aaaaa", "responseinfor:datas==" + datas);

                            JSONObject data = new JSONObject(datas);
                            String sub_code = data.optString("sub_code");
                            Log.d("aaaaa", "responseinfor:sub_code==" + sub_code);

                            // String codeUrl = data.optString("codeUrl"); //"weixin://wxpay/bizpayur1?pr=oXvPsPhzz";// jsonObject.optString("codeUrl");
                            //  String orderId = data.optString("orderId"); //"1611267799286546432";//jsonObject.optString("orderId");

                            //    CartDatas.getCartDatas().setCurrentOredrNumbers(orderId);
                            if (sub_code.equals("SUCCESS")) {

                                String pay_mode_code = data.optString("pay_way_code");
                                CartDatas.getCartDatas().setPay_mode_code(pay_mode_code);
                                HomePages.mHomePages.handlPayOutData();
                                finish();
                            }else{
                                mCheckDataHandler.sendEmptyMessageDelayed(212, 6000);

                            }

                        } else {
                            mCheckDataHandler.sendEmptyMessageDelayed(212, 6000);

                        }


                    } catch (JSONException e) {
                        e.printStackTrace();

                    }
                    break;
            }
        }
    };
    private Handler mCheckDataHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            mCheckDataHandler.removeMessages(212);
            sendRequestPayCodesCheckHttpClient();
        }
    };

    private Handler mRecordDataHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            mCheckDataHandler.removeMessages(212);
            mRecordIndexHandler.removeMessages(201);
            mRecordDataHandler.removeMessages(211);
            //     CartDatas.getCartDatas().clearCartInforsHash();
            finish();
            /*
            if (mProgressIndex == 0) {
                mProgressIndex++;
                WeiboDialogUtils.closeDialog(mWeiboDialog);
                mRecordDataHandler.sendEmptyMessageDelayed(211, 5000);
                return;
            }
            Intent intent = new Intent(mContext, PaySuccess.class);
            intent.putExtra("devicenums", mdevicenums);
            intent.putExtra("imageInfors", mimageInfors);

            startActivity(intent);
            finish();
            */

        }
    };
    private Handler mRecordIndexHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            mRecordIndexHandler.removeMessages(201);
            mCurrentIndex--;
            if (mCurrentIndex > 0) {
                mRecordIndexHandler.sendEmptyMessageDelayed(201, 1000);
                String tempb = mContext.getString(R.string.pay_code_bottom_cancel_texts) + " ( " + String.valueOf(mCurrentIndex) + " s ) ";
                pay_code_bottom_cancel.setText(tempb);
            } else {
                mCurrentIndex = 0;
                mCheckDataHandler.removeMessages(212);
                //  CartDatas.getCartDatas().clearCartInforsHash();
                finish();
            }


        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_codes);
        getSupportActionBar().hide();
        int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
        Window myWindow = this.getWindow();
        myWindow.setFlags(flag, flag);
        Intent intent = getIntent();
        mOrderInfors = "";
        mdevicenums = Urlinfor.getmUrlinfor().mdevicenums;
        mimageInfors = "";

        mContext = this;

        long currentTime = System.currentTimeMillis();
        pay_code_mid_top_order_str = mdevicenums + String.valueOf(currentTime);
        //  CartDatas.getCartDatas().setCurrentNumbers(pay_code_mid_top_order_str);
        String timeNow = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(currentTime);
        // CartDatas.getCartDatas().setCurrentTimes(timeNow);
        Log.d("aaaaa", "timestamptimeNow==" + timeNow);
        String timestamp = CartDatas.getCartDatas().getmOrdernums();//Urlinfor.getmUrlinfor().getTimestamp();
        pay_code_mid_top_time_str = timeNow;
        pay_code_mid_order_str = mdevicenums + timestamp;
        //  CartDatas.getCartDatas().setCurrentOredrNumbers(pay_code_mid_order_str);
        Log.d("aaa", "onCreate:getPrices=" + CartDatas.getCartDatas().getmSpecifData().getPrices());
        mAllPrices = (float) Float.valueOf(CartDatas.getCartDatas().getmSpecifData().getPrices());

        //   HashMap<Long, ArrayList<HomepageGridRightMenuItemData>> allCartInforsHash = CartDatas.getCartDatas().getAllCartInforsHash();
        JSONObject object = new JSONObject();
        int index = 1;
            /*
        try {
            JSONArray jsonarray = new JSONArray();

            for (Long keys : allCartInforsHash.keySet()) {
               // ArrayList<HomepageGridRightMenuItemData> lista = CartDatas.getCartDatas().getCartInforsHash(keys);
                //if (lista.size() > 0) {
                  //  HomepageGridRightMenuItemData homepageGridRightMenuItemData = lista.get(0);
                    JSONObject objecta = new JSONObject();
                    //objecta.put("goodsId", String.valueOf(homepageGridRightMenuItemData.getMenuId()));
                   // objecta.put("price", String.valueOf(homepageGridRightMenuItemData.getprices()));

//                    int nums = lista.size();
//                    objecta.put("amount", nums);
//                    objecta.put("index", index);
//                    objecta.put("position", "");
//                    objecta.put("md5Code", "");
//                    objecta.put("saleStatus", 1);
//                    objecta.put("takeStatus", 1);
//
//                    index++;
//                    float prices = (float)0.1;//Float.valueOf(homepageGridRightMenuItemData.getprices());
//                    mAllPrices += prices * nums;
//                    jsonarray.put(objecta);
//                }
            }

            // object.put("goodsItems", jsonarray );
            mOrderInfors = jsonarray.toString();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
         */
        initView();
        hideBottomUIMenu();
        mCurrentIndex = mAllIndex;

        String tempb = mContext.getString(R.string.cart_view_bottom_back_btn_texts) + " ( " + String.valueOf(mCurrentIndex) + " s ) ";
        pay_code_bottom_cancel.setText(tempb);
        mRecordIndexHandler.sendEmptyMessageDelayed(201, 1000);
        sendRequestPayCodesInitHttpClient();
    }

    private void sendRequestPayCodesCheckHttpClient() {


        new Thread(new Runnable() {

            @Override
            public void run() {
                String strUrl = Urlinfor.getmUrlinfor().getRequestGetPayChecks();
                URL url = null;
                try {
                    long currentTime = System.currentTimeMillis();
                    String timeNow = new SimpleDateFormat("yyyy-MM-dd").format(currentTime);
                    url = new URL(strUrl);
                    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
                    //  urlConn.setRequestProperty("_appId", Urlinfor.getmUrlinfor()._appId);
                    //   String timestamp = "";//Urlinfor.getmUrlinfor().getTimestamp();
                    //   String sign ="";// Urlinfor.getmUrlinfor().getSign(timestamp);
                    //   Log.d("aaaaa", "timestamp:==" + timestamp);
                    //   Log.d("aaaaa", "sign:==" + sign);
                    //    urlConn.setRequestProperty("_timestamp", timestamp);
                    //    urlConn.setRequestProperty("_sign", sign);
                    urlConn.setDoInput(true);
                    urlConn.setDoOutput(true);
                    urlConn.setRequestMethod("POST");
                    urlConn.setUseCaches(false);
                    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    urlConn.setRequestProperty("Charset", "utf-8");
                    /*
                    if (urlConn instanceof HttpsURLConnection) {
                        try {
                            SSLContext sslContext = HttpsUtil.getSSLContextWithCer();

                            if (sslContext != null) {
                                SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
                                ((HttpsURLConnection) urlConn).setDefaultSSLSocketFactory(sslSocketFactory);

                            }
                        } catch (Exception e) {
                            e.printStackTrace();

                        }

                    }

                     */
                    urlConn.connect();

                    Log.d("aaaaa", "timeNow:==" + timeNow);
                    // Log.d("aaaaa", "orderId=orderId=" + CartDatas.getCartDatas().getCurrentOredrNumbers());

                    DataOutputStream dop = new DataOutputStream(urlConn.getOutputStream());
                    dop.writeBytes("devicenums=" + Urlinfor.getmUrlinfor().getMdevicenums());
                    dop.writeBytes("&ordernums=" + CartDatas.getCartDatas().getmOrdernums());
                    dop.writeBytes("&out_order_no=" + CartDatas.getCartDatas().getOut_order_no());
                    dop.writeBytes("&plat_trx_no=" + CartDatas.getCartDatas().getPlat_trx_no());
                    dop.writeBytes("&bank_order_no=" + CartDatas.getCartDatas().getBank_order_no());
                    // dop.writeBytes("&channel=" + Urlinfor.getmUrlinfor().mPayNumbers);
                    // dop.writeBytes("&goodsItems=" + mOrderInfors);

                    //     dop.writeBytes("&version=" + Urlinfor.getmUrlinfor().getVersion());
                    dop.flush();
                    dop.close();
                    BufferedReader bufferReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                    String result = "";
                    String readline = null;
                    while ((readline = bufferReader.readLine()) != null) {
                        result += readline;
                    }
                    bufferReader.close();
                    urlConn.disconnect();
                    //  String a = result.substring(0,result.length()/ 3);
                    //  String b= result.substring(result.length()/ 3,result.length()*2/ 3);
                    //  String c= result.substring(result.length()*2/ 3,result.length());
                    Log.d("aaaaa", "sendRequestPayCodesCheckHttpClient=aaa=" + result);
                    //   Log.d("aaaaa", "minqq=aa=" + a);

                    // Log.d("aaaaa", "minqq=aaa=" + b);
                    // Log.d("aaaaa", "minqq=aaaaaa=" + c);


                    if (result.length() > 0) {
                        String resulta = result;

                        Message msg = new Message();
                        String str1;
                        str1 = resulta;
                        msg.what = PAYCODE_CHECK;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    }


                } catch (IOException e) {

                    Log.d("aaaaa", "222=");

                    e.printStackTrace();
                }

            }
        }).start();//这个start()方法不要忘记了

    }

    private void sendRequestPayCodesInitHttpClient() {


        new Thread(new Runnable() {

            @Override
            public void run() {
                String strUrl = Urlinfor.getmUrlinfor().getPayCodes();
                URL url = null;
                try {
                    long currentTime = System.currentTimeMillis();
                    String timeNow = new SimpleDateFormat("yyyy-MM-dd").format(currentTime);
                    url = new URL(strUrl);
                    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
                    //  urlConn.setRequestProperty("_appId", Urlinfor.getmUrlinfor()._appId);
                    String timestamp = "";//Urlinfor.getmUrlinfor().getTimestamp();
                    String sign = "";//Urlinfor.getmUrlinfor().getSign(timestamp);
                    Log.d("aaaaa", "timestamp:==" + timestamp);
                    Log.d("aaaaa", "sign:==" + sign);
                    //   urlConn.setRequestProperty("_timestamp", timestamp);
                    //   urlConn.setRequestProperty("_sign", sign);
                    urlConn.setDoInput(true);
                    urlConn.setDoOutput(true);
                    urlConn.setRequestMethod("POST");
                    urlConn.setUseCaches(false);
                    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    urlConn.setRequestProperty("Charset", "utf-8");
                        /*
                    if (urlConn instanceof HttpsURLConnection) {
                        try {
                            SSLContext sslContext = HttpsUtil.getSSLContextWithCer();

                            if (sslContext != null) {
                                SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
                                ((HttpsURLConnection) urlConn).setDefaultSSLSocketFactory(sslSocketFactory);

                            }
                        } catch (Exception e) {
                            e.printStackTrace();

                        }

                    }

                         */
                    urlConn.connect();

                    Log.d("aaaaa", "timeNow:==" + timeNow);
                    Log.d("aaaaa", "orderInfor=mOrderInfors=" + mOrderInfors);

                    DataOutputStream dop = new DataOutputStream(urlConn.getOutputStream());
                    dop.writeBytes("devicenums=" + Urlinfor.getmUrlinfor().getMdevicenums());
                    dop.writeBytes("&prices=" + "0.01");//CartDatas.getCartDatas().getmSpecifData().getPrices()  );
                    dop.writeBytes("&goodsid=" + CartDatas.getCartDatas().getmSpecifData().getTypeid());

                    dop.writeBytes("&ordernums=" + CartDatas.getCartDatas().getmOrdernums());
                    dop.writeBytes("&names=" + URLEncoder.encode(CartDatas.getCartDatas().getmNames(), "utf-8"));
                    dop.writeBytes("&storeId=" + Urlinfor.getmUrlinfor().getBrandCodes());
                    dop.writeBytes("&terminalId=" + Urlinfor.getmUrlinfor().getShopInformationNo());
                    Log.d("aaa", "run:storeId=" + Urlinfor.getmUrlinfor().getBrandCodes());
                    Log.d("aaa", "run:terminalId=" + Urlinfor.getmUrlinfor().getShopInformationNo());
                    // dop.writeBytes("&createTime=" + pay_code_mid_top_time_str);

                    //     dop.writeBytes("&version=" + Urlinfor.getmUrlinfor().getVersion());
                    dop.flush();
                    dop.close();
                    BufferedReader bufferReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                    String result = "";
                    String readline = null;
                    while ((readline = bufferReader.readLine()) != null) {
                        result += readline;
                    }
                    bufferReader.close();
                    urlConn.disconnect();
                    //  String a = result.substring(0,result.length()/ 3);
                    //  String b= result.substring(result.length()/ 3,result.length()*2/ 3);
                    //  String c= result.substring(result.length()*2/ 3,result.length());
                    Log.d("aaaaa", "orderInfor=aaa=" + result);
                    //   Log.d("aaaaa", "minqq=aa=" + a);

                    // Log.d("aaaaa", "minqq=aaa=" + b);
                    // Log.d("aaaaa", "minqq=aaaaaa=" + c);


                    if (result.length() > 0) {
                        String resulta = result;

                        Message msg = new Message();
                        String str1;
                        str1 = resulta;
                        msg.what = PAYCODE_INFOR;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    }


                } catch (IOException e) {

                    Log.d("aaaaa", "222=");

                    e.printStackTrace();
                }

            }
        }).start();//这个start()方法不要忘记了

    }


    private void initView() {
        home_page_top_right_device_textview = findViewById(R.id.home_page_top_right_device_textview);
        String dtempb = mContext.getResources().getString(R.string.home_page_top_left_text) + "(" + mdevicenums + ")";

        home_page_top_right_device_textview.setText(dtempb);

        home_page_top_right_image_btn = findViewById(R.id.home_page_top_right_image_btn);

        home_page_top_right_image_btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {


            }
        });

        pay_code_bottom_cancel = findViewById(R.id.pay_code_bottom_cancel);

        pay_code_bottom_cancel.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                mRecordIndexHandler.removeMessages(201);
                mCheckDataHandler.removeMessages(212);
                //   CartDatas.getCartDatas().clearCartInforsHash();
                finish();

            }
        });


        pay_code_mid_top_order_textview = findViewById(R.id.pay_code_mid_top_order_textview);

        String tempc = mContext.getString(R.string.pay_code_mid_top_order_text) + pay_code_mid_top_order_str;
        pay_code_mid_top_order_textview.setText(tempc);

        pay_code_mid_top_time_textview = findViewById(R.id.pay_code_mid_top_time_textview);
        pay_code_mid_top_time_textview.setText(pay_code_mid_top_time_str);

        pay_code_mid_bottom_order_pay_textview = findViewById(R.id.pay_code_mid_bottom_order_pay_textview);

        DecimalFormat fnum = new DecimalFormat("##0.00");

        String dd = fnum.format(mAllPrices);
        pay_code_mid_bottom_order_pay_textview.setText("¥ " + dd);


        iv_qrcode = findViewById(R.id.iv_qrcode);


        //  initServices();
        mWeiboDialog = WeiboDialogUtils.createLoadingDialog(mContext, mContext.getResources().getString(R.string.dialog_loading_texts));
        mProgressIndex = 0;
        //  mRecordDataHandler.sendEmptyMessageDelayed(211, 5000);
    }


    private void generateQrcodeAndDisplay() {

        width = mContext.getResources().getDimension(R.dimen.code_width);
        height = mContext.getResources().getDimension(R.dimen.code_height);


        if (content.length() <= 0) {
            Toast.makeText(this, "你没有输入二维码内容哟！", Toast.LENGTH_SHORT).show();
            return;
        }

        qrcode_bitmap = QRCodeUtil.createQRCodeBitmap(content, (int) width, (int) height, "UTF-8",
                error_correction_level, margin, color_black, color_white, logoBitmap, 0.2F, blackBitmap);
        iv_qrcode.setImageBitmap(qrcode_bitmap);
    }


    /**
     * 隐藏虚拟按键，并且全屏
     */
    protected void hideBottomUIMenu() {
        //隐藏虚拟按键，并且全屏
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
            View v = this.getWindow().getDecorView();
            v.setSystemUiVisibility(View.GONE);
        } else if (Build.VERSION.SDK_INT >= 19) {
            //for new api versions.
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }
    }
}